package com.demo.plugin;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

import com.demo.enums.DataSourceEnum;
import com.demo.util.CustomerContextHolder;
import com.demo.util.DataSourceA;
import com.demo.util.DataSourceB;

@Aspect
public class MultipleDataSourceAspectAdvice {
	
    @Around("execution(* com.demo.mapper..*.*(..))")
    public Object doAround(ProceedingJoinPoint jp) throws Throwable {
        if (jp.getTarget() instanceof DataSourceB) {
        	CustomerContextHolder.setDataSource(DataSourceEnum.DataSourceB);
        }if (jp.getTarget() instanceof DataSourceA) {
        	CustomerContextHolder.setDataSource(DataSourceEnum.DataSourceA);
        } 
        return jp.proceed();
    }
}
